package friends;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FirstMapper extends Mapper<LongWritable, Text,Text,Text> {
    //封装数据
    Text  k = new Text();
    Text  v = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.获取一行数据A:B,C,D,F,E,O
        String line = value.toString();
        //2.切分数据
        String[] fields = line.split(":");
        //3.获取号主数据（主用户）
        String user = fields[0];
        //设置号主为key
        k.set(user);
        //4.获取号主的好友数据列表B,C,D,F,E,O
        String[] friends = fields[1].split(",");
        //5.遍历好友列表
        for (String firend: friends) {
            //设置号主的好友为value
            v.set(firend);
            //6.写出
            context.write(k,v);
       }



    }

}
